﻿<template>
    <el-container>
        <el-header>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
                    <el-form-item label="点单机构" label-width="100px">
                        <el-select
                            placeholder="---请选择点单机构---"
                            v-model="queryList.posStoreCode"
                            style="width: 300px"
                            collapse-tags
                            collapse-tags-tooltip
                        >
                            <el-option
                                v-for="item in posStoreOrgs"
                                :key="item.posStoreCode"
                                :label="item.posStoreName"
                                :value="item.posStoreCode"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="物料编码" label-width="100px">
                        <el-input
                            placeholder="---请输入编码---"
                            v-model="queryList.materialCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料名称" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.materialName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料规格" label-width="100px">
                        <el-input
                            placeholder="---请输入物料规格---"
                            v-model="queryList.materialSpecs"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="点单商品编码" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.goodsCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="点单商品名称" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.goodsName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="点单商品规格" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.standard"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料分类" label-width="100px">
                        <el-tree-select
                            placeholder="---请选择物料分类---"
                            collapse-tags
                            collapse-tags-tooltip
                            v-model="queryList.materialTypeIds"
                            :props="{ label: 'label', value:'value',children: 'children' }"
                            :data="materialTypeTree"
                            multiple
                            :render-after-expand="false"
                            show-checkbox
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="点单分类" label-width="100px">
                        <el-tree-select
                            placeholder="---请选择点单分类---"
                            collapse-tags
                            collapse-tags-tooltip
                            v-model="queryList.goodsTypes"
                            :props="{ label: 'name', value:'code',children: 'children' }"
                            :data="goodTypeTree"
                            multiple
                            :render-after-expand="false"
                            show-checkbox
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label-width="100px" label="库存单位">
                        <el-select
                            placeholder="---请选择单位---"
                            v-model="queryList.unitCode"
                            style="width: 300px"
                        >
                            <el-option
                                v-for="item in optionsUnit"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="销售时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.consumeTimes"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="销售单号" label-width="100px">
                        <el-input
                            placeholder="---请输入销售单号---"
                            v-model="queryList.consumeCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="销售价格" label-width="100px">
                        <el-input-number v-model="queryList.goodsMinPrice" :min="0" :max="queryList.goodsMaxPrice">
                            <template #prefix>
                                <span>￥</span>
                            </template>
                        </el-input-number>至
                        <el-input-number v-model="queryList.goodsMaxPrice" :min="queryList.goodsMinPrice">
                            <template #prefix>
                                <span>￥</span>
                            </template>
                        </el-input-number>
                    </el-form-item>
                    <el-form-item label="金额" label-width="100px">
                        <el-input-number v-model="queryList.goodsMinPay" :min="0" :max="queryList.goodsMaxPay">
                            <template #prefix>
                                <span>￥</span>
                            </template>
                        </el-input-number>至
                        <el-input-number v-model="queryList.goodsMaxPay" :min="queryList.goodsMinPay">
                            <template #prefix>
                                <span>￥</span>
                            </template>
                        </el-input-number>
                    </el-form-item>
                    <el-form-item label-width="100px" label="状态">
                        <el-select
                            placeholder="---请选择状态---"
                            v-model="queryList.consumeState"
                            style="width: 300px"
                        >
                        <el-option label="---请选择---" value />
                        <el-option label="已点单" value="0" />
                        <el-option label="已买单" value="1" />
                        </el-select>
                    </el-form-item>
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>

        <el-main class="nopadding">
            <scTable
                ref="mytable"
                :queryType="'pos-sale/org-sale-pages'"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                row-key="posMaterialCompareId"
                key="posMaterialCompareId"
                stripe
                show-summary
                remoteSummary
            >
                <!-- <el-table-column label="操作" fixed="right" align="center" min-width="180">
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opShow(scope.row, scope.$index)"
                            >查看</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                :disabled="!editState"
                                v-show="isShow"
                                @click="opEdit(scope.row, scope.$index)"
                            >编辑</el-button>
                            <el-popconfirm
                                title="确定删除吗？"
                                @confirm="opDelete(scope.row, scope.$index)"
                            >
                                <template #reference>
                                    <el-button
                                        text
                                        type="primary"
                                        size="small"
                                        v-show="isShow"
                                        :disabled="!deleteState"
                                    >删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column> -->
            </scTable>
        </el-main>
    </el-container>
</template>

<script>
import publicjs from "@/api/model/publicjs"; 
import tool from "@/utils/tool";
import config from "@/config";
export default {
    name: "saleOrder",
    components: {
        publicjs,
    },
    data() {
        return {
            dialogSave: false,
            showCondition: false,
            selectionRows: [],
            pkList: ["itemCode"],
            columnList: [
                  {prop:"materialCode",label:"物料编号",width:"240",sortable:false},  
                  {prop:"materialName",label:"物料名称",width:"240",sortable:false},  
                  {prop:"materialSpecs",label:"物料规格",width:"160",sortable:false},
                  {prop:"consumeTime",label:"销售时间",width:"170",sortable:false},
                  {prop:"consuemCode",label:"销售单号",width:"160",sortable:false},
                  {prop:"materialTypeName",label:"物料分类",width:"140",sortable:false},
                  {prop:"unitName",label:"物料单位",width:"110",sortable:false},
                  {prop:"goodsCode",label:"点单商品编号",width:"160",sortable:false},  
                  {prop:"goodsName",label:"点单商品名称",width:"160",sortable:false},  
                  {prop:"standard",label:"点单商品规格",width:"160",sortable:true},
                  {prop:"uomName",label:"点单商品单位",width:"160",sortable:true},
                  {prop:"orderQty",label:"数量",width:"100",sortable:false},
                  {prop:"salePrice",label:"单价",width:"110",sortable:false},
                  {prop:"totalAmt",label:"金额",width:"120",sortable:false},
                  {prop:"roomName",label:"桌台",width:"110",sortable:false},
                  {prop:"processState",label:"状态",width:"120",sortable:false},
            ],
            OrderList: { itemCode: "Asc" },
            queryList: {
                materialTypeIds: [],
            },
            result: "", // 运行结果
            props1: {
                checkStrictly: true,
                emitPath: false,
            },
            addState: true, //可以增加
            editState: true, //可以修改
            editBatchState: true, //可以批量修改
            deleteState: true, //可以删除
            optionsState: [],
            materialTypeTree: [],
            optionsBrand: [],
            optionsUnit: [],
            goodTypeTree:[],
            posStoreOrgs:[],
            isShow:true,//是否显示
            defaultTime:[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ]
        };
    },
    methods: {
        //添加
        opAdd() {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.open("Add");
            });
        },
        //编辑
        opEdit(row) {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.open("Edit").setData(row);
            });
        },
        //查看
        opShow(row) {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.open("Show").setData(row);
            });
        },
        //删除
        async opDelete(row) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "pos-material-compare/delete",
                    { posMaterialCompareIds: [row.posMaterialCompareId] }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //批量删除
        async opBatchDelete() {
            // eslint-disable-next-line no-debugger
            //debugger;
            this.$confirm(
                `确定删除选中的 ${this.selectionRows.length} 项吗？`,
                "提示",
                {
                    type: "warning",
                }
            )
                .then(async () => {
                    const posMaterialCompareIds = this.selectionRows.map(
                        (p) => p.posMaterialCompareId
                    );
                    try {
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "pos-material-compare/delete",
                                { posMaterialCompareIds: [...posMaterialCompareIds] }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$refs.mytable.getData();
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        return false;
                    }
                })
                .catch(() => {});
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
        },
        //本地更新数据
        handleSaveSuccess(data, mode) {
            if (mode == "Add") {
                this.$refs.mytable.refresh();
            } else if (mode == "Edit") {
                this.$refs.mytable.refresh();
            }
        },
        async opBindData() {
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        resetSearch() {
            this.queryList = {};
        },
        async initOptions() {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    { Codes: ["Status"] }
                );
                if (returnValue.status == 200) {
                    this.optionsState = returnValue.response.find(
                        (p) => p.code == "Status"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "material-type/tree",
                    { status: 1 }
                );
                if (returnValue.status == 200) {
                    this.materialTypeTree = returnValue.response;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/dic-options",
                    { ParentBaseDictionaryCodes: ["001", "002"] }
                );
                if (returnValue.status == 200) {
                    this.optionsBrand = returnValue.response.find(
                        (p) => p.code == "001"
                    ).optionsDetails;
                    this.optionsUnit = returnValue.response.find(
                        (p) => p.code == "002"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "store/pos-org-cnfigs",
                    {}
                );
                if (returnValue.status == 200) {
                    this.posStoreOrgs = returnValue.response;
                    this.queryList.posStoreCode=this.posStoreOrgs[0].posStoreCode;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "pos-sale/org-type",
                    { posStoreCode:this.posStoreOrgs[0].posStoreCode}
                );
                if (returnValue.status == 200) {
                    this.goodTypeTree = returnValue.response;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
    },
    async mounted() {
        var orgType = tool.data.get("USER_INFO").AccountType;
        if(orgType==1) 
        {
            this.isShow=true;
        }
        console.log(orgType,this.isShow);
        await this.initOptions();
        await this.opBindData();
    },
};
</script>
